<template>
  <div>
    <div class="top">
      <div class="top-title">考核试卷</div>
      <!-- <div>
        <div v-for="(item, index) in jibies" :key="index" class="top-jibie shou" :class="index_jibie === index?'top-select':''" @click="index_jibie=index">{{item.name}}</div>
      </div> -->
    </div>
    <div class="body">
      <div class="body1">
        <!-- <el-table
          max-height="500px"
          :header-cell-style="{
            'background-color': '#E4EEFF',
            'height': '54px',
            'color': '#000000',
            'font-size': '14px',
            'font-weight': 'bold'
        }"
          :data="table"
          size="mini"
          empty-text="暂无数据"
          stripe
          style="width: 100%">
          <el-table-column
            label="题号"
            align="center"
            width="80">
             <template slot-scope="scope">
                {{scope.$index + 1}}
            </template>
          </el-table-column>
          <el-table-column
            label="分数"
            align="center"
            width="100">
             <template slot-scope="scope">
                {{scope.row.name}}
            </template>
          </el-table-column>
          <el-table-column
            label="题目">
             <template slot-scope="scope">
                <span :title="scope.row.name">{{scope.row.name}}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="120">
             <template slot-scope="scope">
                <el-button type="text" @click="xiangqing(scope)">详情</el-button>
            </template>
          </el-table-column>
        </el-table> -->
        <!-- <div class="body-title">
          <span style="margin-left:40px">情景题</span>
        </div> -->
        <div v-for="(item, index) in table" :key="index">
          <div class="body-title">
            <span style="margin-left:40px">{{item.questionBirefDetail.typeId==3?'情景题':'案例题'}}</span>
          </div> 
          <div class="timus">
            <div class="timu">{{item.questionBirefDetail.titleDescription}}</div>
            <div class="timu" v-if="item.questionBirefDetail.typeId==3"><span style="font-weight:bold">所需材料：</span>{{JSON.parse(item.questionBirefDetail.questionTitle.title).text}}</div>
            <div class="qingjing-images" v-if="item.questionBirefDetail.typeId==3">
              <el-image class="qingjing-image" v-for="(item, index) in JSON.parse(item.questionBirefDetail.questionTitle.title).images" :key="index" :src="item" />
            </div>
          </div>
          <div class="xian"></div>
          <div class="body2" v-if="item.questionBirefDetail.typeId==4">
            <div class="body-title1">
              考生作答:
            </div>
            <div class="body-text">
              {{item.examineeAnswer}}
            </div>
          </div>
          <div class="body2">
            <div class="body-title1">
              解析:
            </div>
            <div class="body-text">
              {{item.questionBirefDetail.analyses}}
            </div>
          </div>
          <div class="dafen">
            <el-input class="dafen-input" type="number" min="0" v-model="answers[index].score" placeholder="请输入" />
            <!-- <div v-else class="dafen-text2 shou" @click="panduan1=true">请输入</div> -->
            <div class="dafen-text1">请给本题作出评分（满分{{item.questionBirefDetail.score}}分）：</div>
          </div>
        </div>
      </div>
      <div class="bottom">
        <div class="tijiao shou" @click="tijiao()">提交成绩</div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import $http from '@/utils/request'
import $httpJSON from '@/utils/requestJSON'

export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  data () {
    return {
      span1: 3,
      span2: 9,
      panduan1: false,
      panduan2: false,
      dialogAdd: false,
      index_jibie: 0,
      value: '',
      values: [],
      table: [],
      answers: [],
      form: {}
    }
  },
  mounted() {
    let form = JSON.parse(localStorage.getItem('info'))
    $http.get('/examiner/query/examineepaper/' + this.$route.query.examId, {params: {
      examineeId: this.$route.query.id,
      paperId: this.$route.query.paperId
    }}).then(response => {
        if (response.success) {
          response.data.forEach(item=> {
            this.answers.push({
              questionId: item.questionBirefDetail.id,
              score: ''
            })
          })
          this.table = response.data
        } else  {
          this.$message({
            message: response.msg,
            type: 'error',
            duration: 2000
          })
        }
        
      }).catch(error => {
        console.log(error)
      })
  },
  methods: {
    toPeople(item) {
      this.$router.push({
          path:"/people",//目标路径
          query:{
              id: 1,//要传的值
          }
      })
    },
    xiangqing(item) {
      console.log(item)
    },
    tijiao() {
      console.log(this.answers)
      for (let i = 0; i < this.answers.length; i++) {
        if (this.answers[i].score + '' === '') {
          this.$message.success('第' + (i+1) +  '道题分数不能为空')
          return
        }
        if (this.answers[i].score < 0) {
          this.$message.success('第' + (i+1) +  '道题分数不能低于0分')
          return
        }
        if (this.table[i].questionBirefDetail.score < this.answers[i].score) {
          this.$message.success('第' + (i+1) +  '道题分数不能超过' + this.table[i].questionBirefDetail.score + '分')
          return
        }
      }
      this.$confirm('此操作将提交打分记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let query = {
            examId: this.$route.query.examId,
            examineeId: this.$route.query.id,
            questionAndScoreForm: this.answers
          }
           $httpJSON.post('/examiner/submit/examinee/score', query).then(response => {
                if (response.success) {
                  this.$message({
                    type: 'success',
                    message: '操作成功!'
                  })
                  this.$router.back()
                } else {
                  this.$message({
                    message: response.data||response.msg,
                    type: 'error',
                    duration: 2000
                  })
                }
                
              }).catch(error => {
                console.log(error)
              })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.top-jibie{
  float: left;
  width: 60px;
  height: 46px;
  margin-right: 30px;
  color: rgba(153, 153, 153, 100);
  font-size: 14px;
  text-align: center;
  font-family: PingFangSC-Regular;
  display: flex;
  justify-content: center;
  align-items: center;
}
.top-select {
  color: #1890FF;
  border-bottom: 2px solid #1890FF;
}
.top-title{
  // margin-top: -20px;
  float: left;
  width: 100px;
  height: 40px;
  font-size: 16px;
  color: rgba(51, 51, 51, 100);
  font-size: 20px;
  display: flex;
  // justify-content: center;
  // align-items: center;
}
.body{
  display: flex;
  justify-content: space-around;
  // align-items: center;
  flex-wrap: wrap;

  width:100%;
  padding: 24px;
  
}
.body1{
  width: 100%;
  background-color: white;
  
}
.bottom{
  width:100%;
  height:170px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.tijiao{
  width:140px;
  height:47px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  font-weight:bold;
  color: white;
  border-radius: 4px;
  background-color: rgba(24, 144, 255, 1);
}
.body-title {
  // margin: 30px 0 30px 0;
  background-color: #E4EEFF;
  height: 54px;
  display: flex;
  align-items: center;
  color: #000000;
  font-weight:bold;
  font-size: 14px;
}
.xian{
  width:100%;
  height: 1px;
  background-color:#E8E8E8;
}
.body2{
  margin-left: 40px;;
  width:calc(100% - 80px);
}
.body-title1 {
  height: 64px;
  display: flex;
  align-items: center;
  color: #000000;
  font-weight:bold;
  font-size: 18px;
}
.timus{
  width: 100%;
  padding: 20px 35px 0 35px;
}
.timu{
  margin-bottom: 11px;
  font-size: 16px;
}
.qingjing-images{
  width:100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.qingjing-image{
  width:200px;
  height: 130px;
  margin-bottom: 20px;
}
.body-text{
  width:100%;
  padding: 20px 20px 30px 20px;
  border: 1px solid rgba(219, 219, 219, 1);
}
.dafen{
  width:100%;
  height:73px;
  margin: 20px 0 20px 0;
}
.dafen-text1{
  float: right;
  line-height:73px;
  font-size:18px;
  font-weight: bold;
}
.dafen-text2{
  float: right;
  margin-right:40px;
  width: 174px;
  line-height:73px;
  font-size:18px;
  color: #FFFFFF;
  border-radius: 4px;
  background-color: rgba(24, 144, 255, 1);
}
.dafen-input{
  float: right;
  margin-right:40px;
  width: 174px;
  height:73px;
  line-height: 73px;
}
</style>
